<?php
namespace jy_lianfeeshop;
defined('BY_JYA') or exit('error');
/*
	分销商分佣计算
	
*/
class commission extends \plugin{
	/*
		生成分佣
	*/
	function create($order){
		if(!$this->setting['isopen']){
			return false;
		}
		//$this->model('model')->create_feechi($order);
		$this->order=$order;		
		$this->commission_order=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$this->order['mid'],
			'ordersn'=>$this->order['ordersn'],
			'order_price'=>$this->order['price'],
			'commission_money'=>0,
			'createtime'=>TIMESTAMP,
		);
		//1、默认方式: 除运费和会员折扣(或促销折扣)外其他所有费用全部计算分佣；实际支付方式: 只计算实际支付和余额抵扣部分的分佣(包括余额支付)
		if($this->setting['commissiontype']==2){
			$this->commission_order['commission_price']=$this->order['price'];
		}else{
			$this->commission_order['commission_price']=$this->order['price']-$this->order['dispatchprice'];
		}
		$member=$this->get('member',array('mid'=>$this->order['mid'],'uniacid'=>$_SESSION['uniacid']));
		if(!$member['id']){
			$member=$this->model('member')->register(array(),true);
		}
		$this->gei_mid=$member['gei_mid'];
		//付费时才归属AB
		if($member['fromuser'] && $this->gei_mid==0){
			$this->gei_mid=$this->model('member')->gei_member($member);
			if(!$member['isbuy']){
				$member=$this->get('member',array('mid'=>$this->order['mid'],'uniacid'=>$_SESSION['uniacid']));
			}
		}
		$this->commission_order['teamid']=$member['fromuser'];
		if($member['level_id'] && $member['is_agent']){
			$this->nowlevel=$this->getcolumn('level',array('id'=>$member['level_id']),'level');
		}else{
			$this->nowlevel=0;
		}
		$this->create_redcommission($member);
		$indata=$this->commission_order;
		unset($indata['isarea']);
		unset($indata['maxlevel']);
		$this->insert('order',$indata);
		//自购升级
		if($member['mid']){
			$this->model('member')->update_agent_level($member['mid'],true);
		}
		return true;
	}
	/*
		级差分佣type=1;lastmoney2,晋级奖励的感恩
	*/
	function create_redcommission($member=array()){
			$agent=$this->get('member',array('mid'=>$member['fromuser'],'uniacid'=>$_SESSION['uniacid']));
			$isbuy=pdo_count('jy_lianfeeshop_order',array('mid'=>$this->order['mid'],'uniacid'=>$_SESSION['uniacid']));
			//AB线
			if($this->gei_mid>0){
				$gei_agent=$this->get('member',array('mid'=>$this->gei_mid,'uniacid'=>$_SESSION['uniacid']));
				$this->lastmoney=0;
			}else{
				$jianfromuser=$agent['gei_mid']>0?$agent['gei_mid']:$agent['fromuser'];
				if($jianfromuser){
					$gei_agent=$this->get('member',array('mid'=>$jianfromuser,'uniacid'=>$_SESSION['uniacid']));
				}
			}
			if($this->gei_mid==$agent['mid']){
				$this->isteding=true;
			}
			if(!$agent['is_agent'] && !$gei_agent['is_agent']){
				return false;
			}
			if($gei_agent['mid'] && !$gei_agent['is_agent']){
				$gei_agent['mid']=0;
			}
			if(!$agent['level_id']){
				$level=$this->plugin_setting('default_level');
				$level_id=0;
			}else{
				$level=$this->get('level',array('id'=>$agent['level_id'],'uniacid'=>$_SESSION['uniacid']));
				$level_id=$level['id'];
			}
			$zhi1_per1=$level['zhi1_per1'];
			$zhi1_per2=$level['zhi1_per2'];
			$zhi2_per1=$level['zhi2_per1'];
			$zhi2_per2=$level['zhi2_per2'];
			$zhi3_per1=$level['zhi3_per1'];
			$zhi3_per2=$level['zhi3_per2'];
			$zhi4_per=$level['zhi4_per'];
			$zhi4_per2=$level['zhi4_per2'];
			$fugou_per=$level['fugou_per'];
			$zhi1_fee1=0;
			$zhi1_fee2=0;
			$zhi2_fee1=0;
			$zhi2_fee2=0;
			$zhi3_fee1=0;
			$zhi3_fee2=0;
			$zhi4_fee=0;
			$zhi4_fee2=0;
			$fugou_fee=0;
			$order_price=$this->commission_order['commission_price'];
			$remark=array(
				'level_id'=>$level_id,
				'order_price'=>$order_price,
				'goods_commission'=>array(),
			);
			//先检查是否存在商品独立分佣规则，如果存在则对订单相应商品部分金额单独计算分佣
			$this->needorder=false;
			foreach($this->order['goods'] as $goods){
				$ignore=$this->get('goods',array('goods_id'=>$goods['goodsid'],'uniacid'=>$_SESSION['uniacid']));
				if(!$ignore['id']){
					$this->needorder=true;
					continue;
				}
				if($ignore['ignore']){
					$goods_commission=array();
					$order_price=$order_price-$goods['total_price'];
					continue;
				}else{
					$goods_commission=$ignore['commissions']?json_decode($ignore['commissions'],true):array();
				}
				$order_price=$order_price-$goods['total_price'];
				$goodspers=array();
				$demogoodspers=array();
				foreach($goods_commission as $gc){
						if($gc['level_id']==0){
							$demogoodspers=$gc;
						}
						if($gc['level_id']!=$level_id){
							continue;
						}else{
							$goodspers=$gc;
							break;
						}
				}
				$goodspers=$goodspers?:$demogoodspers;
				$goodszhi1_per1=$goodspers['zhi1_per1'];
				$goodszhi1_per2=$goodspers['zhi1_per2'];
				$goodszhi2_per1=$goodspers['zhi2_per1'];
				$goodszhi2_per2=$goodspers['zhi2_per2'];
				$goodszhi3_per1=$goodspers['zhi3_per1'];
				$goodszhi3_per2=$goodspers['zhi3_per2'];
				$goodszhi4_per=$goodspers['zhi4_per'];
				$goodszhi4_per2=$goodspers['zhi4_per2'];
				$goodsfugou_per=$goodspers['fugou_per'];
				if($isbuy){
					//复购奖
					if(substr($goodsfugou_per,-1)=='%'){
						$fee=($goods['total_price']*substr($goodsfugou_per,0,-1))/100;
					}else{
						$fee=$goodsfugou_per*$goods['total'];
					}
					$fugou_fee +=$fee;
				}else{
					//第1人推荐奖
					if($member['frank']==1){
						if(substr($goodszhi1_per1,-1)=='%'){
							$fee=($goods['total_price']*substr($goodszhi1_per1,0,-1))/100;
						}else{
							$fee=$goodszhi1_per1*$goods['total'];
						}
						$zhi1_fee1 +=$fee;
						if(substr($goodszhi1_per2,-1)=='%'){
							$fee=($goods['total_price']*substr($goodszhi1_per2,0,-1))/100;
						}else{
							$fee=$goodszhi1_per2*$goods['total'];
						}
						$zhi1_fee2 +=$fee;
					}
					//第2人推荐奖
					if($member['frank']==2){
						if(substr($goodszhi2_per1,-1)=='%'){
							$fee=($goods['total_price']*substr($goodszhi2_per1,0,-1))/100;
						}else{
							$fee=$goodszhi2_per1*$goods['total'];
						}
						$zhi2_fee1 +=$fee;
						if(substr($goodszhi2_per2,-1)=='%'){
							$fee=($goods['total_price']*substr($goodszhi2_per2,0,-1))/100;
						}else{
							$fee=$goodszhi2_per2*$goods['total'];
						}
						$zhi2_fee2 +=$fee;
					}
					//第3人推荐奖
					if($member['frank']==3){
						if(substr($goodszhi3_per1,-1)=='%'){
							$fee=($goods['total_price']*substr($goodszhi3_per1,0,-1))/100;
						}else{
							$fee=$goodszhi3_per1*$goods['total'];
						}
						$zhi3_fee1 +=$fee;
						if(substr($goodszhi3_per2,-1)=='%'){
							$fee=($goods['total_price']*substr($goodszhi3_per2,0,-1))/100;
						}else{
							$fee=$goodszhi3_per2*$goods['total'];
						}
						$zhi3_fee2 +=$fee;
					}
					//第4人推荐奖
					if($member['frank']>3){
						if(substr($goodszhi4_per,-1)=='%'){
								$fee=($goods['total_price']*substr($goodszhi4_per,0,-1))/100;
						}else{
								$fee=$goodszhi4_per*$goods['total'];
						}
						$zhi4_fee +=$fee;
						
					}
					//特定人ＡＢ推荐奖
					if(substr($goodszhi4_per2,-1)=='%'){
						$fee=($goods['total_price']*substr($goodszhi4_per2,0,-1))/100;
					}else{
						$fee=$goodszhi4_per2*$goods['total'];
					}
					$zhi4_fee2 +=$fee;
				}
				$remark['goods_commission'][]=array('goods_id'=>$goods['goodsid'],'total_price'=>$goods['total_price'],'total'=>$goods['total']);
			}
			if($order_price>0 || ($this->order['goods'] && $this->needorder)){
				if($isbuy){
					//复购奖
					if(substr($fugou_per,-1)=='%'){
						$fee=($order_price*substr($fugou_per,0,-1))/100;
					}else{
						$fee=$fugou_per*$goods['total'];
					}
					$fugou_fee +=$fee;
				}else{
					//第1人推荐奖
					if($member['frank']==1){
						if(substr($zhi1_per1,-1)=='%'){
							$fee=($order_price*substr($zhi1_per1,0,-1))/100;
						}else{
							$fee=$zhi1_per1*$goods['total'];
						}
						$zhi1_fee1 +=$fee;
						if(substr($zhi1_per2,-1)=='%'){
							$fee=($order_price*substr($zhi1_per2,0,-1))/100;
						}else{
							$fee=$zhi1_per2*$goods['total'];
						}
						$zhi1_fee2 +=$fee;
					}
					//第2人推荐奖
					if($member['frank']==2){
						if(substr($zhi2_per1,-1)=='%'){
							$fee=($order_price*substr($zhi2_per1,0,-1))/100;
						}else{
							$fee=$zhi2_per1*$goods['total'];
						}
						$zhi2_fee1 +=$fee;
						if(substr($zhi2_per2,-1)=='%'){
							$fee=($order_price*substr($zhi2_per2,0,-1))/100;
						}else{
							$fee=$zhi2_per2*$goods['total'];
						}
						$zhi2_fee2 +=$fee;
					}
					//第3人推荐奖
					if($member['frank']==3){
						if(substr($zhi3_per1,-1)=='%'){
							$fee=($order_price*substr($zhi3_per1,0,-1))/100;
						}else{
							$fee=$zhi3_per1*$goods['total'];
						}
						$zhi3_fee1 +=$fee;
						if(substr($zhi3_per2,-1)=='%'){
							$fee=($order_price*substr($zhi3_per2,0,-1))/100;
						}else{
							$fee=$zhi3_per2*$goods['total'];
						}
						$zhi3_fee2 +=$fee;
					}
					//第4人推荐奖
					if($member['frank']>3){
						if(substr($zhi4_per,-1)=='%'){
								$fee=($order_price*substr($zhi4_per,0,-1))/100;
						}else{
								$fee=$zhi4_per*$goods['total'];
						}
						$zhi4_fee +=$fee;
					}
					if(substr($zhi4_per2,-1)=='%'){
							$fee=($order_price*substr($zhi4_per2,0,-1))/100;
					}else{
							$fee=$zhi4_per2*$goods['total'];
					}
					$zhi4_fee2 +=$fee;
				}
			}
			if($fugou_fee>0 && ($agent['is_agent'] || $gei_agent['mid'])){
				$this->commission_order['commission_money']+=$fugou_fee;
				$new_commission=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$gei_agent['mid']?:$agent['mid'],
					'agent_id'=>$gei_agent['id']?:$agent['id'],
					'level'=>$level_id,
					'ordersn'=>$this->order['ordersn'],
					'money'=>$fugou_fee,
					'remark'=>ijson_encode($remark),
					'createtime'=>TIMESTAMP,
					'status'=>$this->setting['is_jiesuan']?:0,
					'type'=>9,
				);
				$this->insert('commission',$new_commission);
			}
			if($zhi1_fee1>0 && $agent['is_agent'] && !$this->isteding){
				$this->commission_order['commission_money']+=$zhi1_fee1;
				$new_commission=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$agent['mid'],
					'agent_id'=>$agent['id'],
					'level'=>$level_id,
					'ordersn'=>$this->order['ordersn'],
					'money'=>$zhi1_fee1,
					'remark'=>ijson_encode($remark),
					'createtime'=>TIMESTAMP,
					'status'=>$this->setting['is_jiesuan']?:0,
					'type'=>1,
				);
				$this->insert('commission',$new_commission);
			}
			if($zhi1_fee2>0 && !$this->isteding){
				$this->commission_order['commission_money']+=$zhi1_fee2;
				$new_commission=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$gei_agent['mid']?:$agent['mid'],
					'agent_id'=>$gei_agent['id'],
					'level'=>$level_id,
					'ordersn'=>$this->order['ordersn'],
					'money'=>$zhi1_fee2,
					'remark'=>ijson_encode($remark),
					'createtime'=>TIMESTAMP,
					'status'=>$this->setting['is_jiesuan']?:0,
					'type'=>2,
				);
				$this->insert('commission',$new_commission);
			}
			if($zhi2_fee1>0 && $agent['is_agent'] && !$this->isteding){
				$this->commission_order['commission_money']+=$zhi2_fee1;
				$new_commission=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$agent['mid'],
					'agent_id'=>$agent['id'],
					'level'=>$level_id,
					'ordersn'=>$this->order['ordersn'],
					'money'=>$zhi2_fee1,
					'remark'=>ijson_encode($remark),
					'createtime'=>TIMESTAMP,
					'status'=>$this->setting['is_jiesuan']?:0,
					'type'=>3,
				);
				$this->insert('commission',$new_commission);
			}
			if($zhi2_fee2>0 && !$this->isteding){
				$this->commission_order['commission_money']+=$zhi2_fee2;
				$new_commission=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$gei_agent['mid']?:$agent['mid'],
					'agent_id'=>$gei_agent['id'],
					'level'=>$level_id,
					'ordersn'=>$this->order['ordersn'],
					'money'=>$zhi2_fee2,
					'remark'=>ijson_encode($remark),
					'createtime'=>TIMESTAMP,
					'status'=>$this->setting['is_jiesuan']?:0,
					'type'=>4,
				);
				$this->insert('commission',$new_commission);
			}
			if($zhi3_fee1>0 && $agent['is_agent'] && !$this->isteding){
				$this->commission_order['commission_money']+=$zhi3_fee1;
				$new_commission=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$agent['mid'],
					'agent_id'=>$agent['id'],
					'level'=>$level_id,
					'ordersn'=>$this->order['ordersn'],
					'money'=>$zhi3_fee1,
					'remark'=>ijson_encode($remark),
					'createtime'=>TIMESTAMP,
					'status'=>$this->setting['is_jiesuan']?:0,
					'type'=>5,
				);
				$this->insert('commission',$new_commission);
			}
			if($zhi3_fee2>0 && !$this->isteding){
				$this->commission_order['commission_money']+=$zhi3_fee2;
				$new_commission=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$gei_agent['mid']?:$agent['mid'],
					'agent_id'=>$gei_agent['id'],
					'level'=>$level_id,
					'ordersn'=>$this->order['ordersn'],
					'money'=>$zhi3_fee2,
					'remark'=>ijson_encode($remark),
					'createtime'=>TIMESTAMP,
					'status'=>$this->setting['is_jiesuan']?:0,
					'type'=>6,
				);
				$this->insert('commission',$new_commission);
			}
			if($zhi4_fee>0 && $agent['is_agent'] && !$this->isteding){
				$this->commission_order['commission_money']+=$zhi4_fee;
				$new_commission=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$agent['mid'],
					'agent_id'=>$agent['id'],
					'level'=>$level_id,
					'ordersn'=>$this->order['ordersn'],
					'money'=>$zhi4_fee,
					'remark'=>ijson_encode($remark),
					'createtime'=>TIMESTAMP,
					'status'=>$this->setting['is_jiesuan']?:0,
					'type'=>7,
				);
				$this->insert('commission',$new_commission);
			}
			if($zhi4_fee2>0 && $gei_agent['is_agent'] && $this->isteding){
				$this->commission_order['commission_money']+=$zhi4_fee2;
				$new_commission=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$gei_agent['mid'],
					'agent_id'=>$agent['id'],
					'level'=>$level_id,
					'ordersn'=>$this->order['ordersn'],
					'money'=>$zhi4_fee2,
					'remark'=>ijson_encode($remark),
					'createtime'=>TIMESTAMP,
					'status'=>$this->setting['is_jiesuan']?:0,
					'type'=>8,
				);
				$this->insert('commission',$new_commission);
			}
			//判断是否存在分销商
			$this->commission_order['isarea']=true;
	}
	/*
		订单完成时，把分佣状态由初始的订单待完成升级为待结算
	*/
	public function order_complete($order){
		$this->update('commission',array('status'=>1,'complete_time'=>TIMESTAMP),array('ordersn'=>$order['ordersn'],'status'=>0));
	}
	/*
		解冻
	*/
	public function jie_dong($mid=0){
		$mid=$mid?:$_SESSION['uid'];
		if(!$mid){
			return false;
		}
		$params=array('dong_fee >'=>0,'isjiedong'=>0,'uniacid'=>$_SESSION['uniacid'],'mid'=>$mid);
		$dong_fee=$this->getsum('commission',$params,'dong_fee');
		if($dong_fee<=0){
			return false;
		}
		$new_commission=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$mid,
					'money'=>$dong_fee,
					'remark'=>'解冻分佣',
					'createtime'=>TIMESTAMP,
					'status'=>1,
					'type'=>2,
		);
		$this->insert('commission',$new_commission);
		$this->update('commission',array('isjiedong'=>1),$params);
		$this->update('member',array('isjiedong'=>1),array('mid'=>$mid));
		return true;
	}
	/*
		创建结算单
	*/
	public function create_balance($mid,$post=array()){
		$type=intval($post['type']);
		if(!$mid){
			exi('请先选择要结算的会员！','error');
		}
		if($post['pay_type']=='alipay'){
			if(!$post['realname']){
				exi('请先填写真实姓名！','error');
			}
			if(!$post['alipay']){
				exi('请先填写支付宝帐号！','error');
			}
			if(!$post['alipay1']){
				exi('请确认帐号','error');
			}
			if($post['alipay1']!=$post['alipay']){
				exi('确认帐号与支付宝帐号不匹配！','error');
			}
		}
		if($post['pay_type']=='union'){
			if(!$post['realname']){
				exi('请输入姓名','error');
			}
			if(!$post['bankname']){
				exi('请输入所属银行','error');
			}
			if(!$post['bankcard']){
				exi('请银行卡号','error');
			}
			if(!$post['bankcard1']){
				exi('请确认卡号','error');
			}
			if($post['bankcard']!=$post['bankcard1']){
				exi('确认卡号与银行卡号不匹配！','error');
			}
		}
		if($post['pay_type']!='credit' && $this->setting['balance_fapiao'] && !$post['fatype'] && !$post['faimages']){
			exi('请上传电子发票！','error');
		}
		//获取可结算分佣
		$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mid,'status'=>1);
		if($this->setting['balance_day']){
			//结算天数
			$time=TIMESTAMP-intval($this->setting['balance_day'])*86400;
			$params['complete_time <']=$time;
		}
		if($type){
			$params['type']=$type;
			$isgetfee=$this->model('member')->check_isgetfee($mid,$type);
			if($isgetfee){
				exi('您已结算过了该奖金！不能再结算！','error');
			}
		}
		$commissions=$this->getall('commission',$params);
		if(!$commissions){
			exi('没有可结算的分佣！','error');
		}
		$commission_num=count($commissions);
		$money=0;
		$jifen=0;
		foreach($commissions as $commission){
			$money+=$commission['money'];
		}
		if($this->setting['balance_jifen']){
			$jifen=$money*$this->setting['balance_jifen']/100;
			$money=$money-$jifen;
		}
		//结算最低分佣检测
		if($money<$this->setting['balance_fee']){
			exi('满￥'.$this->setting['balance_fee'].'才可结算！','error');
		}
		$new_balance=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$mid,
			'balancesn'=>get_ordersn($this->tablename('commission'),'balancesn','AC'),
			'commission_num'=>$commission_num,
			'money'=>$money,
			'jifen'=>$jifen,
			'pay_type'=>$post['pay_type'],
			'realname'=>$post['realname'],
			'alipay'=>$post['alipay'],
			'bankname'=>$post['bankname'],
			'bankcard'=>$post['bankcard'],
			'fatype'=>$post['fatype'],
			'faimages'=>ijson_encode($post['faimages']),
			'createtime'=>TIMESTAMP,
			'fee_type'=>$type,
			'status'=>0,
		);
		//结算手续费
		if($this->setting['balance_per']){
			$new_balance['balance_pay']=intval($new_balance['money']*$this->setting['balance_per'])/100;
		}else{
			$new_balance['balance_pay']=0;
		}
		$new_balance['final_money']=$new_balance['money']-$new_balance['balance_pay'];
		$this->insert('balance',$new_balance);
		$balance_id=pdo_insertid();
		$update=array(
				'status'=>2,
				'balancesn'=>$new_balance['balancesn'],
		);
		$this->update('commission',$update,$params);
		return $balance_id;
	}
	/*
		审核结算单
	*/
	public function check_balance($balance_id,$status,$remark=''){
		$update=array(
			'status'=>$status,
			'check_time'=>TIMESTAMP,
			'remark'=>$remark,
		);
		$this->update('balance',$update,array('id'=>$balance_id));
	}
	/*
		打款结算单
	*/
	public function pay_balance($balance_id,$pay_type){
		$balance=$this->get('balance',array('id'=>$balance_id,'uniacid'=>$_SESSION['uniacid']));
		if(!$balance || $balance['status']!=1){
			exi('结算单不存在或者不符合打款条件，打款失败！','error');
		}
		$pay_types=array_keys($this->pay_types);
		if(!$pay_type || !in_array($pay_type,$pay_types)){
			exi('未设置打款方式或者打款方式不合法，打款失败！','error');
		}
		$func_name='pay_balance_by_'.$pay_type;
		$trade_no=$this->$func_name($balance['mid'],$balance['final_money'],$balance['balancesn']);
		$update=array(
			'status'=>3,
			'pay_type'=>$pay_type,
			'pay_trade_no'=>$trade_no,
			'pay_time'=>TIMESTAMP,
		);
		$this->update('balance',$update,array('id'=>$balance['id']));
		if($balance['jifen']>0){
			cfc('core')->member_credit($balance['mid'],'credit1',$balance['jifen'],true,$this->plugin_name,$remark='佣金转积分');
		}
		return true;
	}
	/*
		打款到余额
	*/
	protected function pay_balance_by_credit($mid,$money,$balancesn){
		return cfc('core')->member_credit($mid,'credit2',$money,true,$this->plugin_name,$remark='分销分佣打款');
	}
	/*
		打款到微信零钱
	*/
	protected function pay_balance_by_wechat($mid,$money,$balancesn){
		$params=array(
			'openid'=>$mid,
			'mch_billno'=>$balancesn,
			'money'=>$money,
			'remark'=>'代理商分佣发放',
		);
		$res=cfc('wechat_pay')->mch_pay($params);
		return $res['payment_no']?:$res['batch_id'];
	}
	/*
		打款到支付宝
	*/
	protected function pay_balance_by_alipay($mid,$money,$balancesn){
		return true;
		exi('暂不支持打款到支付宝！','error');
	}
	/*
		打款到银行账户
	*/
	protected function pay_balance_by_union($mid,$money,$balancesn){
		return true;
		exi('暂不支持打款到银行账户！','error');
	}

	public function commission_remark($remark){
		if(!$remark){
			return '';
		}
		$remark=json_decode($remark,true);
		$goods_str='';
		if($remark['goods_commission']){
			foreach($remark['goods_commission'] as $goods){
				$goods['title']=pdo_getcolumn('jy_weishop_goods',array('id'=>$goods['goods_id']),'title');
				$goods_str.="商品ID【{$goods['goods_id']}】，商品名称【{$goods['title']}】，商品数量【{$goods['total']}】，商品总价【{$goods['total_price']}】，分佣规则【{$goods['commission_per']}】，分销分佣【{$goods['commission_money']}】\n";
			}
		}else{
			$goods_str='';
		}
		$remark['level_title']=pdo_getcolumn('jy_lianfeeshop_level',array('uniacid'=>$_SESSION['uniacid'],'level'=>$remark['level_id']),'title');
		$remark['level_title']=$remark['level_title']?:'默认等级';
		$remark_str=<<<TPL
分销商等级ID【{$remark['level_id']}】，等级名称【{$remark['level_title']}】，分佣等级【{$remark['commission_level']}】，订单总价【{$remark['order_price']}】
商品独立分佣：
{$goods_str}
订单分佣：
除去设置独立分佣的商品外订单金额【{$remark['order_commission']['order_price']}】，分佣规则【{$remark['order_commission']['commission_per']}%】，分销分佣【{$remark['order_commission']['commission_money']}】
分佣总计：【{$remark['commission_money']}】
TPL;
		return $remark_str;
	}
}